<?php
/*
 * Copyright 2010 Johannes M. Schmitt
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * GoogleClosureCSSRenamingMap tests.
 */
include dirname(__FILE__).'/../../../../../../../../test/bootstrap/unit.php';

$t = new lime_test(6);

// get all closure css files
$cssBasePath = dirname(dirname(dirname(__FILE__))).'/fixtures/css/';
$cssFiles = sfFinder::type('file')->name('*.css')->in($cssBasePath);

// General Tests
$renamingMap = new GoogleClosureCSSRenamingMap();
$renamingMap->addFiles($cssFiles);
$t->is(array_diff($renamingMap->getFiles(), $cssFiles), array(), 'Passed array of files matches returned array.');

// common.css Tests
$renamingMap = new GoogleClosureCSSRenamingMap();
$renamingMap->addFile($cssBasePath.'/common.css');
$classNames = $renamingMap->getClassNames();
$t->is(count($classNames), 1, 'Same classes are not added multiple times.');
$t->ok(isset($classNames['goog-inline-block']), 'Correct class name was extracted.');
$t->is($classNames['goog-inline-block'], 3, 'Number of occurence is correct.');

// charpicker.css Tests
$renamingMap = new GoogleClosureCSSRenamingMap();
$renamingMap->addFile($cssBasePath.'/charpicker.css');
$classNames = $renamingMap->getClassNames();
$actualClasses = array(
  'goog-char-picker' => 1,
  'goog-char-picker-hovercard' => 1,
  'goog-char-picker-unicode' => 1,
  'goog-char-picker-char-zoom' => 1,
  'goog-char-picker-grid-container' => 1,
  'goog-char-picker-grid' => 3,
  'goog-stick' => 1,
  'goog-stickwrap' => 1,
  'goog-char-picker-recents' => 1,
  'goog-char-picker-notice' => 1,
  'goog-char-picker-uplus' => 1,
  'goog-char-picker-input-box' => 1,
  'label-input-label' => 1,
  'goog-char-picker-okbutton' => 1,
  'goog-flat-button' => 1,
  'goog-flat-button-hover' => 1,
  'goog-char-picker-button' => 1,
  'goog-char-picker-menu' => 6,
  'goog-menuitem' => 2,
  'goog-char-picker-menu2' => 1,
  'goog-subtitle' => 1,
  'goog-menuitem-rtl' => 1,
  'goog-menuitem-highlight' => 1,
  'goog-menuseparator' => 1,
);
$t->is($classNames, $actualClasses, 'Classes\' names and occurences are correct.');

// editortoolbar.css Tests
$renamingMap = new GoogleClosureCSSRenamingMap();
$renamingMap->addFile($cssBasePath.'/editortoolbar.css');
$classNames = $renamingMap->getClassNames();
$actualClasses = array (
  'tr-icon' => 2,
  'goog-color-menu-button-indicator' => 1,
  'tr-undo' => 2,
  'goog-toolbar-button-rtl' => 2,
  'tr-redo' => 2,
  'tr-fontName' => 1,
  'goog-toolbar-menu-button-caption' => 3,
  'tr-fontSize' => 1,
  'tr-bold' => 1,
  'tr-italic' => 1,
  'tr-underline' => 1,
  'tr-foreColor' => 1,
  'tr-backColor' => 1,
  'tr-link' => 1,
  'tr-image' => 1,
  'tr-newDrawing' => 1,
  'tr-spChar' => 1,
  'tr-indent' => 2,
  'tr-rtl-mode' => 5,
  'tr-outdent' => 2,
  'tr-insertUnorderedList' => 2,
  'tr-insertOrderedList' => 2,
  'tr-justifyLeft' => 1,
  'tr-justifyCenter' => 1,
  'tr-justifyRight' => 1,
  'tr-justifyFull' => 1,
  'tr-BLOCKQUOTE' => 2,
  'tr-removeFormat' => 1,
  'tr-spell' => 1,
  'tr-ltr' => 1,
  'tr-rtl' => 1,
  'tr-insertModule' => 1,
  'tr-strikeThrough' => 1,
  'tr-subscript' => 1,
  'tr-superscript' => 1,
  'tr-equation' => 1,
  'tr-editHtml' => 1,
  'tr-formatBlock' => 1,
);
$t->is($classNames, $actualClasses, 'Classes\' names and occurences are correct.');
